package com.zzsy.carosshopprojects.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.king.base.adapter.ViewHolderRecyclerAdapter;
import com.king.base.adapter.holder.ViewHolder;
import com.yatoooon.screenadaptation.ScreenAdapterTools;
import com.zzsy.carosshopprojects.R;
import com.zzsy.carosshopprojects.bean.SpaceCourseDataBean;
import com.zzsy.carosshopprojects.util.ConverterHelper;
import com.zzsy.carosshopprojects.util.StringUtils;

import java.math.BigDecimal;
import java.util.List;

public class MineRadioAdapter extends ViewHolderRecyclerAdapter<SpaceCourseDataBean> {
    private static final int MYLIVE_MODE_CHECK = 0;
    int mEditMode = MYLIVE_MODE_CHECK;

    public MineRadioAdapter(Context context, List<SpaceCourseDataBean> listData, int layoutId) {
        super(context, listData, layoutId);
    }

    @Override
    public View buildConvertView(LayoutInflater layoutInflater, ViewGroup parent, int viewType) {
        View view = layoutInflater.inflate(R.layout.adapter_item_course_tab, null);
        ScreenAdapterTools.getInstance().loadView(view);
        return view;
    }

    @Override
    public void bindViewDatas(ViewHolder helper, SpaceCourseDataBean bean, int positions) {
        ImageView mCheckBox = helper.getView(R.id.check_box);
        String preKind = bean.getPreKind();
        if (!StringUtils.isEmpty(preKind)) {
            if ("1".equals(preKind)) {
                double money = ConverterHelper.toBigDecimal(bean.getPreAmount()).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                helper.setText(R.id.tv_yg_money, "￥" + money);
            } else {
                double rebate = ConverterHelper.toBigDecimal(bean.getRebate()).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
                helper.setText(R.id.tv_yg_money, rebate + "折");
            }
        }


        if (!StringUtils.isEmpty(bean.getEndTime())) {
            helper.setText(R.id.tv_time_gq, "过期时间:" + bean.getEndTime());
        }
        if (!StringUtils.isEmpty(bean.getCouponName())) {
            helper.setText(R.id.tv_counp_name, bean.getCouponName());
        }
        if (bean.isCheck()) {
            mCheckBox.setImageResource(R.mipmap.hexiao_select);
        } else {
            mCheckBox.setImageResource(R.mipmap.hexiao_no);
        }

//        if (mEditMode == MYLIVE_MODE_CHECK) {
//            mCheckBox.setVisibility(View.GONE);
//        } else {
//            mCheckBox.setVisibility(View.VISIBLE);
//            if (bean.isCheck()) {
//                mCheckBox.setImageResource(R.mipmap.hexiao_select);
//            } else {
//                mCheckBox.setImageResource(R.mipmap.hexiao_no);
//            }
//        }

    }
    public void setEditMode(int editMode) {
        mEditMode = editMode;
        notifyDataSetChanged();
    }

}
